package com.feng.demo.jakartacommons.lang;
import org.apache.commons.lang.NumberRange;
import org.apache.commons.lang.NumberUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;

public class LangDemo{

	public static void main(String args[]){

		new LangDemo().test();
	}

	public void test(){

		// -- StringUtils methods
		System.err.println("===== StringUtils methods =====");

		// pads and centers a string with the specified string around it
		System.err.println(StringUtils.center("name", 8, "Da"));

		// removes everything from a string after the specified separator
		System.err.println(StringUtils.chomp("TVGuide", "Guid"));

		// returns how many times a substring occurs in the given string
		System.err.println(StringUtils.countMatches("DumDeeDumDeeDumDaDa", "Dee"));

		// deletes all white spaces from the given string
		System.err.println(StringUtils.deleteWhitespace(" Whit e  Spa ce   "));

		// replaces all occurances of a string with the given string
		System.err.println(StringUtils.replace("DaDaDumDee", "Dum", "Doo"));

		// reverses a string
		System.err.println(StringUtils.reverse("1234567"));

		// -- RandomStringUtils methods
		System.err.println("===== RandomStringUtils methods =====");

		// creates a random string of specified length and contains numbers
		System.err.println(RandomStringUtils.random(8, true, true));

		// -- NumberUtils methods
		System.err.println("===== NumberUtils methods =====");

		// prints the maximum of the three numbers
		System.err.println(NumberUtils.maximum(8, 5, -9));

		// prints the minimum of the three numbers
		System.err.println(NumberUtils.minimum(8, 5, -9));

		// -- NumberRange methods
		System.err.println("===== NumberRange methods =====");

		// create a number range object with -10 as the min and 10 as the max
		NumberRange nr = new NumberRange(new Integer(-10), new Integer(10));

		// returns whether the number is included in this range
		System.err.println("Includes 0? " + nr.includesNumber(new Integer(0)));

		// -- Builder Methods - Require the Mortgage class
		System.err.println("===== Builder methods =====");
		Mortgage mortgage1 = new Mortgage();
		mortgage1.setYears(25);
		mortgage1.setRate(4.55f);

		Mortgage mortgage2 = new Mortgage();
		mortgage2.setYears(25);
		mortgage2.setRate(4.56f);

		// returns the toString representation of this mortgage class using '
		// ToStringBuilder
		System.err.println("Mortgage 1: " + mortgage1.toString());

		// checks whether Mortgage1 is equal to Mortgage2 using ToEqualsBuilder
		System.err.println("Is Mortgage 1 is equal to Mortgage 2? " +
			mortgage1.equals(mortgage2));

		// -- Enum Methods - Require the OnTV class
		System.err.println("===== Enum methods =====");

		// grab a value from the Enum
		System.err.println("From OnTV Enum, Idol item: " + OnTV.getEnum("Idol"));


	}
}